package com.flower.exception;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *  自定义异常处理器
 *  目的：出错了，转发到/WEB-INF/message.jsp页面，友好提示出错信息
 *  注：将自定义异常处理器加入到IOC容器中（Spring.xml中进行配置）
 */
public class MyExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        // ModelAndView -> request域中的
        ModelAndView mav = new ModelAndView();
        mav.addObject("message", "系统出错，请联系管理员");
        mav.setViewName("WEB-INF/message");
        return mav;
    }
}
